import json

from flask import Flask,jsonify

from mongoConnection import mongo
#这个是用来解决序列化问题的
#from JsonEncoder__没用只是不想删了 import MyEncoder
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
def record_is_existed(seedwordkey):
    seedwordkey = mongo.db.searchRecords.find({"name":seedwordkey},{})
    #如果没有从数据库中查到，就该值就为True
    return any(seedwordkey)

def insert_record(seedwordkey):
    mongo.db.searchRecords.insert_one({"name":seedwordkey})
    return True


def save_midwordkeys(seedwordkey,midwordkeylist):
    mongo.db.midWordKeys.insert_one({"seedwordkey": seedwordkey, "midwordkeys": midwordkeylist})
    return True

def find_compwordkeys(seedwordkey):
    seedwordkey = mongo.db.compWordKeys.find({"seedwordkey":seedwordkey},{"_id" : 0})
    result = {}
    for i in seedwordkey:
        result[i["seedwordkey"]] = i["compwordkeys"]
    return result

def save_compwordkeys(seedwordkey,compwordkeys):
    mongo.db.compWordKeys.insert_one({"seedwordkey":seedwordkey,"compwordkeys":compwordkeys})
    return True

